var Oimg = new Image();
var MaxWidth = 72;
var MaxHeight = 72;
var maxbytes = 49;
var defaultSrc = "/images/common/img_df70.gif";
function getimg(obj, imgid) {
	var strRegex = /\.((jpg)|(gif)|(bmp)|(png)|(jpeg))$/ig;
	var re = new RegExp(strRegex);
	if (!re.test(obj.value)) {
		alert("您指定的图片不存在或图片格式不合适，请检查后重试。");
		clearFileInput(obj);
		document.getElementById(imgid).src = defaultSrc;
	} else {
		Oimg = document.getElementById(imgid);
		if (window.XMLHttpRequest) {
			if (!window.ActiveXObject) {
				Oimg.src = obj.files.item(0).getAsDataURL();
			} else {
				obj.select();
				Oimg.src = document.selection.createRange().text;
			}
		} else {
			Oimg.src = obj.value;
		}
		DownImage(Oimg);
	}
}
function DownImage(ImgD,id){
    var image=new Image(); 
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){ 
     if(image.width==28&&image.height==30){
     ImgD.width=72;
     ImgD.height=72;
     ImgD.src=defaultSrc;
     }
     else{
		var rate = (MaxWidth/image.width < MaxHeight/image.height)?MaxWidth/image.width:MaxHeight/image.height;
	if(rate <= 1){			
		ImgD.width = image.width*rate;
		ImgD.height =image.height*rate;
	}else{
		ImgD.width = image.width;
		ImgD.height =image.height;
	}}}	
    document.getElementById(imgid).src = ImgD.src;
	}
function DownImage(ImgD) {
	var image = new Image();
	image.src = ImgD.src;
	if (image.width > 0 && image.height > 0) {
		if (image.width == 28 && image.height == 30) {
			ImgD.width = 72;
			ImgD.height = 72;
			ImgD.src = defaultSrc;
		} else {
			var rate = (MaxWidth / image.width < MaxHeight / image.height) ? MaxWidth
					/ image.width
					: MaxHeight / image.height;
			if (rate <= 1) {
				ImgD.width = image.width * rate;
				ImgD.height = image.height * rate;
			} else {
				ImgD.width = image.width;
				ImgD.height = image.height;
			}
		}
	}
}


function loadImage(obj) {
	var image = new Image();
	image.src = obj.src;
	if (image.width > 0 && image.height > 0) {
		var rate = (MaxWidth / image.width < MaxHeight / image.height) ? MaxWidth
				/ image.width
				: MaxHeight / image.height;
		if (rate <= 1) {
			obj.width = image.width * rate;
			obj.height = image.height * rate;
		} else {
			obj.width = image.width;
			obj.height = image.height;
		}
	}
	if (document.all) {
		obj.style.marginTop = 4 + "px";
	}
}

function clearFileInput(fl) {
	var form = document.createElement("form");
	document.body.appendChild(form);
	var pos = fl.parentNode;
	form.appendChild(fl);
	form.reset();
	pos.appendChild(fl);
	document.body.removeChild(form);
}